---
title: Replace the stored web context for an application and session
summary: Save end-to-end process on SAIF.Services.WCF.Services.WebContextService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-22
operation_id: OP-010
trigger: Caller invokes `Save` over the `WebContext` route.
---

# OP-010: Replace the stored web context for an application and session

Save is invoked over the `WebContext` route on `SAIF.Services.WCF.Services.WebContextService`; this page documents the process end to end, from route dispatch to the message the caller receives.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-010 |
| **Trigger** | Caller invokes `Save` over the `WebContext` route. |
| **Entry operation** | [`Save`](../contracts/web-context-service.md#save) |
| **Owning component** | `SAIF.Services.WCF.Services.WebContextService.Save` |
| **Inputs** | Request message parts listed below |
| **Outputs** | No response payload (void) |
| **Failure behavior** | Generic SOAP fault, per [Faults and error pipeline](../faults.md) |

## Request and response

| Direction | Element | Type | Declared in | Notes |
| --- | --- | --- | --- | --- |
| Request | `applicationName` | `string` | BCL (`System`) | Application name portion of the context key. (Yes) |
| Request | `sessionId` | `string` | BCL (`System`) | Session id portion of the context key. (Yes) |
| Request | `context` | `IWebContext` | External contracts assembly (`SAIF.Services.WCF.Contracts` / framework closure) ** | The context whose entries are persisted. (Yes) |
| Response | `void` | `void` | n/a (void) | Not applicable. |

<!-- Types declared in `SAIF.Services.WCF.Contracts` are attributed to `SAIF.Framework.Core`, inferred from source and package references and marked `*`; their members are not enumerated because the external declaration was not read, marked `**`. -->

## Steps

1. `Enforce.ArgumentNotNullOrEmpty` on `applicationName` and `sessionId`, `Enforce.ArgumentNotNull` on `context` ([BR-WCF-014](../business-rules.md#br-wcf-014-web-context-operations-require-identifying-arguments)).
   - On failure: `ArgumentNullException`, logged and surfaced as a generic SOAP fault.
2. `unitOfWork.Begin()`.
3. Query and `Delete` every existing `WebContextItem` for the application and session ([BR-WCF-017](../business-rules.md#br-wcf-017-web-context-rows-are-read-once)).
4. `Add` one `WebContextItem` per entry returned by `context.GetAll()`, stamping `UpdateDate = DateTime.Now` ([BR-WCF-011](../business-rules.md#br-wcf-011-persisted-changes-stamp-a-local-timestamp)).
5. `unitOfWork.Commit()`.
   - On failure: logged by the installed error handler, surfaced as a generic SOAP fault, and rolled back on `Dispose`.

## Process flow

The following diagram visualizes this process's control flow.

```mermaid
flowchart TD
    A["Validate applicationName, sessionId,<br>and context"]
    B["unitOfWork.Begin()."]
    C["Delete existing context items<br>for application and session"]
    D["Add new context items from<br>context.GetAll()"]
    E["unitOfWork.Commit()."]
    A --> B
    B --> C
    C --> D
    D --> E
```

## Transaction and side effects

| Aspect | Finding |
| --- | --- |
| Unit of work | `SqlServerUnitOfWorkFactory` (`NETFRAMEWORK`/`APPM`) |
| Commit point | `unitOfWork.Commit()` after the delete-then-insert sequence |
| Records written | `WebContextItem` (delete all, then insert) |
| Downstream calls | None |
| Shared state touched | None |
| Repeat-call behavior | Idempotent — replaces the full stored set each time |

## Logging

| Surface | Written content |
| --- | --- |
| `ErrorLogErrorHandler` → `LogService` | Failure-path exception logging only, carrying method signature, calling user and exception detail; see [Faults and error pipeline](../faults.md) |

## Faults and error handling

| Failure | Fault type the caller receives | Produced by | Source |
| --- | --- | --- | --- |
| `ArgumentNullException` | `Generic SOAP fault` | The operation itself, via `Enforce` | src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs |
| SQL Server/NHibernate exception | `Generic SOAP fault` | The `ErrorLogErrorHandler` installed by `[LogErrorBehavior]` | src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs |

## Authorization

| Requirement | Enforced by | Source | Applies to |
| --- | --- | --- | --- |
| [None in code](../authentication-authorization.md#authorization-enforcement) | IIS authentication on the deployment (see [Activation and hosting](../activation-hosting.md)) | `src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs` | This operation |

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Activation and hosting](../activation-hosting.md)
- [Operations](../operations.md)
- [Faults and error pipeline](../faults.md)
- [Authentication and authorization](../authentication-authorization.md)
- [Dependencies](../dependencies.md)
- [Configuration](../configuration.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Data model](../data-model.md)
- [Operational runbook](../operational-runbook.md)
- [Tech debt](../tech-debt.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts. Statements marked with `**` could not be confirmed; treat
> as unknown until verified.

## Sources
- src/WCF/SAIF.Services.WCF.Host/Services/WebContextService.cs
